package yzy.ecps.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.http.HttpServletResponse;

public class EcpsUtils {
	
	/**
	 * 根据key从系统配置文件中获取对应的配置
	 * @param key
	 * @return
	 * @throws IOException 
	 */
	public static String getValueByKeyFormSysProperties(String key) throws IOException{
		InputStream in = EcpsUtils.class.getClassLoader().getResourceAsStream("system.properties");
		Properties prop = new Properties();
		prop.load(in);
		return prop.getProperty(key);
	}
	
	/**
	 * 将字符串以UTF-8编码的方法向浏览器响应
	 * @param result
	 * @param response
	 */
	public static void printResultForUTF8(String result,HttpServletResponse response){
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		try {
			response.getWriter().write(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
